#ifndef INETWORKING_H
#define INETWORKING_H

#include <QObject>
#include "socket/protocol/baseptc.h"
#include <QMap>

class QTcpSocket;
class QDataStream;


class INetWorking : public QObject
{
    Q_OBJECT

public:
    explicit INetWorking(QObject *parent = 0);
    virtual ~INetWorking();

public:
    // param is the parameter that you want to set, and block is the output paramter,
    // which will be conbined with QTcpSocket
    void setData(void* param, QByteArray *block);

    // bytesAvailable means the number of incoming bytes that are waiting to be read.
    bool recieveData(int bytesAvailable, QTcpSocket *pSocket);


    // when we do not recieve any data, we return an empty QMap
    QMap<QString, QString>* getResult();
    // when we do not recieve any data under this name, we return an empty QString
    QString getResult(QString name);

protected:
    // QDataStream is pointer of the stream that corresponds to QTcpSocket,
    // param is the data
    virtual void prepareWriteData(QByteArray* block, void *param) = 0;
    virtual bool prepareReadData(QTcpSocket *pTcpSocket, protocal::BasePtc *basePtc) = 0;
    virtual void formResult() = 0;

signals:
    // when commands sent and recieved are different
    void SendAndRecieveDifferentError();

protected:
    int nextBlockSize;
    QMap<QString, QString> resultMap;

    int source;
    int command;
};

#endif // INETWORKING_H
